﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bus.Bll;
using Bus.Model;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    private tb_user admUser = null;
    private tb_custom cusUser = null;
    private UserModel user = null;
    private CustomModel custM = null;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (adm.Checked)
        {
            //管理人员登录登录
            admUser = new tb_user();
            bool stus = admUser.AdmLogin(username.Text.Trim(), pwd.Text.Trim());
            if (stus)
            {
                DataSet ds = admUser.GetList("[username]='" + username.Text.Trim() + "' and [pwd]='" + pwd.Text.Trim() + "'");
                user = new UserModel();
                user.uid = int.Parse(ds.Tables[0].Rows[0]["uid"].ToString().Trim());
                HttpCookie hc = new HttpCookie("bus_ck_info", "f=0&id="+user .uid);
                hc.Expires = DateTime.Now.AddYears(10);
                Response.Cookies.Add(hc);
                Session["userid"] = user.uid;
                Session["utp"] = 0;
                Response.Redirect("admin/index.aspx");
            }

        }
        else
        {
            //客户登录
            cusUser = new tb_custom();
            bool cus = cusUser.CusLogin(username.Text.Trim(), pwd.Text.Trim());
            if (cus)
            {
                DataSet ds = cusUser.GetList("[cname]='" + username.Text.Trim() + "' and [password]='" + pwd.Text.Trim() + "'");
                custM = new CustomModel();
                custM.cid = int.Parse(ds.Tables[0].Rows[0]["cid"].ToString().Trim());
                var regd = ds.Tables[0].Rows[0]["regdate"].ToString().Trim();
                HttpCookie hc = new HttpCookie("bus_ck_info", "f=1&id="+custM.cid);
                hc.Expires = DateTime.Now.AddYears(10);
                Response.Cookies.Add(hc);
                Session["userid"] = custM.cid;
                Session["utp"] = 1;
                Response.Redirect("admin/index.aspx");
            }
        }
       


        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        username.Text = string.Empty;
        pwd.Text = string.Empty;

    }
}
